package xml_test;

import java.io.IOException;

import junit.framework.Assert;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.junit.Test;

import xml.Dom4JFileReader;


public class Dom4JFileReaderTest
{
	@Test
	public void readDocument() throws DocumentException, IOException
	{
		Dom4JFileReader reader = new Dom4JFileReader();
		Document doc = reader.readDocument("src-test-resources\\test.xml");
		
		Assert.assertNotNull(doc);
		
		Element root = doc.getRootElement();
		Assert.assertEquals("vokabeln", root.getName());
		
		Element vokabel = root.element("vokabel");
		Assert.assertEquals("vokabel", vokabel.getName());
		Assert.assertEquals("idnummer", vokabel.attributeValue("id"));
		
		Element lvlGerman = vokabel.element("lvlGerman");
		Assert.assertEquals("lvlGerman", lvlGerman.getName());
		Assert.assertEquals("0", lvlGerman.attributeValue("lvl"));
		
		Element german = vokabel.element("german");
		Assert.assertEquals("german", german.getName());
		Assert.assertEquals("gehen", german.getText());
		
		Element english = vokabel.element("english");
		Assert.assertEquals("english", english.getName());
		Assert.assertEquals("to go", english.getText());
		
		Element lvlEnglish = vokabel.element("lvlEnglish");
		Assert.assertEquals("lvlEnglish", lvlEnglish.getName());
		Assert.assertEquals("0", lvlEnglish.attributeValue("lvl"));
		
		
	}
}
